package programmercarl.动态规划.C24;

class Solution1 {
    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        dp[0] = 0;//和等于n的最小平方数
        for (int i = 0; i <=n ; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        for (int i = 1; i <= n; i++) {//背包
            for (int j=1; j*j <= i; j++) {
                dp[i] = Math.min(dp[i], dp[i-j*j] + 1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Solution1 solution = new Solution1();
        solution.numSquares(12);
    }
}